/*
 * Copyright (c) 2014 Strong Group - 版权所有
 * 
 * This software is the confidential and proprietary information of
 * Strong Group. You shall not disclose such confidential information 
 * and shall use it only in accordance with the terms of the license 
 * agreement you entered into with www.cnstrong.cn.
 */
package com.zuorenke.serialize.support.hessian;

import com.caucho.hessian.io.Hessian2Input;
import com.fasterxml.jackson.core.type.TypeReference;
import com.zuorenke.serialize.ObjectInput;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;

/**
 *
 * 描述:
 *
 * @author  WQB
 * @created 2014-4-7 上午10:09:14
 * @since   v1.0.0
 */
public class Hessian2ObjectInput implements ObjectInput {
	private final Hessian2Input mH2i;

	public Hessian2ObjectInput(InputStream is) {
		mH2i = new Hessian2Input(is);
		mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
	}

	public boolean readBool() throws IOException {
		return mH2i.readBoolean();
	}

	public byte readByte() throws IOException {
		return (byte) mH2i.readInt();
	}

	public short readShort() throws IOException {
		return (short) mH2i.readInt();
	}

	public int readInt() throws IOException {
		return mH2i.readInt();
	}

	public long readLong() throws IOException {
		return mH2i.readLong();
	}

	public float readFloat() throws IOException {
		return (float) mH2i.readDouble();
	}

	public double readDouble() throws IOException {
		return mH2i.readDouble();
	}

	public byte[] readBytes() throws IOException {
		return mH2i.readBytes();
	}

	public String readUTF() throws IOException {
		return mH2i.readString();
	}

	public Object readObject() throws IOException {
		return mH2i.readObject();
	}

	@SuppressWarnings("unchecked")
	public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
		return (T) mH2i.readObject(cls);
	}

	public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
		return readObject(cls);
	}

	@Override
	public <T> T readObject(TypeReference<?> valueTypeRef) throws IOException, ClassNotFoundException {
		return null;
	}

}